

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;


public class RegisterTest1 extends JFrame{
    StringBuffer s1 = new StringBuffer();
    int[] arr = new int[10];

    RegisterTest1(){
        setTitle("初始界面");
        setBounds(500,500,500,500);
        setLayout(new GridLayout(5,1));

        JPanel jPanel1 = new JPanel();
        JPanel jPanel2 = new JPanel();
        JPanel jPanel3 = new JPanel();
        JPanel jPanel4 = new JPanel();
        JPanel jPanel5 = new JPanel();

        JLabel jLabel1 = new JLabel("账号");
        JLabel jLabel2 = new JLabel("密码");
        JTextField jTextField = new JTextField(12);
        JPasswordField jPasswordField = new JPasswordField(12);
        jPasswordField.setEchoChar('*');
        JButton jButton1 = new JButton("登录");
        JButton jButton2 = new JButton("注册");
        JButton jButton3 = new JButton("推出");
        JButton jButton4 = new JButton("生成");
        JButton jButton5 = new JButton("排序");

        JTextField jTextField1 = new JTextField(20);
        JTextField jTextField2 = new JTextField(20);



        jPanel1.add(jLabel1);jPanel1.add(jTextField);
        jPanel2.add(jLabel2);jPanel2.add(jPasswordField);
        jPanel3.add(jButton1);jPanel3.add(jButton2);jPanel3.add(jButton3);jPanel3.add(jButton4);jPanel3.add(jButton5);
        jPanel4.add(jTextField1);
        jPanel5.add(jTextField2);


        add(jPanel1);add(jPanel2);add(jPanel3);add(jPanel4);add(jPanel5);


        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jButton1){
                    new LogIn1();
                }
            }
        });
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jButton2){
                    new Enroll1();
                }
            }
        });
        jButton3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jButton3){
                    dispose();
                }
            }
        });
        jButton4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jButton4){
                    for (int i = 0;i < 10;i++){
                        //1-100
                        int rand = (int)(Math.random()*99+1);
                        s1.append(rand);
                        s1.append(" ");
                        arr[i] = rand;
                    }
                    jTextField1.setText(String.valueOf(s1));
                }
            }
        });
        jButton5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jButton5){
                    Arrays.sort(arr);
                    jTextField2.setText(Arrays.toString(arr));


                }
            }
        });

        setVisible(true);
    }

    public static void main(String[] args) {
        new RegisterTest1();
    }


}



//点击登录后的窗口类
class LogIn1 extends JFrame{
    LogIn1(){
        setTitle("登录成功");
        setBounds(320,210,250,150);
        System.out.println("登录成功");
        setVisible(true);
    }
}


//点击注册后的窗口类
class Enroll1 extends JFrame {
    Enroll1(){
        setTitle("注册界面");

        setBounds(620,420,300,200);
        JLabel l4 = new JLabel("新建账号");
        JLabel l5 = new JLabel("设置密码");
        JLabel l6 = new JLabel("确认密码");
        JTextField t4 = new JTextField(12);
        JPasswordField pass5 = new JPasswordField(12);
        JPasswordField pass6 = new JPasswordField(12);
        pass5.setEchoChar('*');
        pass6.setEchoChar('*');

        setLayout(new GridLayout(4,1));

        JPanel p5 = new JPanel();
        JPanel p6 = new JPanel();
        JPanel p7 = new JPanel();
        JPanel p8 = new JPanel();

        p5.add(l4);p5.add(t4);
        p6.add(l5);p6.add(pass5);
        p7.add(l6);p7.add(pass6);
        add(p5);add(p6);add(p7);

        JButton jb = new JButton("确认注册");
        p8.add(jb);
        add(p8);

        setVisible(true);

        jb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jb){
                    new EndTest1();
                }
            }
        });
    }

}

//点击注册成功后的窗口类
class EndTest1 extends JFrame{
    EndTest1(){
        setTitle("注册成功界面");
        setBounds(630,420,250,150);
        JLabel jLabel1 = new JLabel("哦，注册成功了!~");
        System.out.println(jLabel1);
        setVisible(true);

    }
}

